/**
 * 酒精灯
 */
Lamp = Widget.extend({
	runningAction:null,
	ctor:function(parent){
		this._super();
		parent.addChild(this,31);
		this.setTag(TAG_LAMP);
		this.init();
		this.initAction();
	},
	init : function(){
		this.setVisible(false);
		this.setCascadeOpacityEnabled(true);

		var lampBody=new Button(this,10,TAG_LAMP_BOTTLE,"#run/lampBottle.png",this.callback,this);
		lampBody.setScale(0.6);

		var lamplid=new Button(this,10,TAG_LAMP_LID,"#run/lampLid.png",this.callback,this);
		lamplid.setScale(0.6);
		lamplid.setPosition(0,60);
		
		this.match=new Button(this,10,TAG_MATCH,"#run/match.png",this.callback,this);
		this.match.setScale(0.15);
		this.match.setPosition(200,20);
		
		this.match1=new Button(this.match,10,TAG_MATCH1,"#run/match2.png",this.callback,this);
		this.match1.setScale(2);
		this.match1.setPosition(this.match.width*0.78,this.match.height*1.1);
		this.match1.setVisible(false);
		
		this.fire=new Button(lampBody,10,TAG_FIRE,"#run/action/1.png",this.callback,this);
		this.fire.setScale(3);
		this.fire.setVisible(false);
		this.fire.setPosition(lampBody.width*0.5,lampBody.height*1.2);
	},
	initAction:function(){
		var animFrames=[];
		for(var i=1;i<4;i++){
			var str="run/action/"+i+".png";
			var frame=cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation=new cc.Animation(animFrames,0.05);
		this.runningAction=cc.animate(animation);
		this.runningAction.retain();
	},
	changeFire:function(){
		this.fire.setVisible(true);
		this.fire.runAction(this.runningAction.repeatForever());
	},
	moveMatch:function(){
		var move=cc.moveBy(1,cc.p(368,-195));
		var ber=cc.bezierBy(1, [cc.p(-50, 15),cc.p(-1000,200),cc.p(-1700,268)]);
		this.match1.runAction(cc.sequence(move,cc.callFunc(function() {
			this.match1.setSpriteFrame("run/match1.png");
		}, this),ber));
	},
	callback:function(p){
		var func=cc.callFunc(function() {
			gg.flow.next();
		}, this);
		switch (p.getTag()) {
		case TAG_LAMP_LID:
			var ber =cc.bezierBy(1, [cc.p(0,35),cc.p(10, 60),cc.p(88, -100)]);
			p.runAction(cc.sequence(ber,func));
			break;
		case TAG_MATCH:
			p.runAction(cc.sequence(cc.callFunc(function() {
				this.match1.setVisible(true);
				this.moveMatch();
			}, this),cc.delayTime(3),cc.callFunc(function() {
				this.match.removeFromParent(true);
				this.changeFire();
			}, this),func));
			break;
		case TAG_LAMP_BOTTLE:
			var ber=cc.bezierBy(1, [cc.p(50,10),cc.p(180,15),cc.p(460,20)]);
			p.runAction(cc.sequence(ber,cc.callFunc(function() {
				ll.run.testtube.addBubble(1);
				ll.run.testtube.fadeinFog();
			}, this),cc.delayTime(6),cc.callFunc(function() {
				this.showTip=new ShowTip("水加热转化为水蒸气,水蒸气具有很大的内能," +
										"\n在其膨胀过程中对软木塞做功使其冲出，进而" +
										"\n水蒸气的内能转化为软木塞的动能",cc.p(gg.width*0.35,gg.height*0.75));
				ll.run.testtube.lidMove();
				ll.run.testtube.changeFog();
				ll.run.testtube.fadeinFog1();
			}, this),cc.delayTime(6),func));
			break;
		default:
			break;
		}
	}
});
